package cn.edu.hust.sse.software7.class3.serviceImpl;

import java.util.List;
import java.util.logging.Logger;

import cn.edu.hust.sse.software7.class3.DAO.EBProductDAO;
import cn.edu.hust.sse.software7.class3.entities.EBProduct;
import cn.edu.hust.sse.software7.class3.service.EBProductService;

public class EBProductServiceImpl implements EBProductService {
	private static Logger log;
	EBProductDAO dao = new EBProductDAO();

	public EBProductServiceImpl() {
		if (dao == null) {
			dao = new EBProductDAO();
		}
		log = Logger.getLogger(EBUserServiceImpl.class.getName());
	}

	@Override
	public boolean isExistProduct(EBProduct prod) {
		return dao.isExistProduct(prod);
	}

	@Override
	public void addProduct(EBProduct product) {
		boolean checkProd = dao.isExistProduct(product);
		if (!checkProd) {
			dao.addProduct(product);
		} else {
			
			log.info("category with the name of " + product.getProductName()
					+ "is already exist.");
		}
	}

	@Override
	public void updateProduct(EBProduct product) {
		dao.updateProduct(product);
	}

	@Override
	public void deleteProduct(EBProduct product) {
		boolean checkExist = dao.isExistProduct(product);
		if (checkExist) {
			dao.deleteProduct(product);
		} else {
			log.info("product with the name of " + product.getProductName()
					+ "is not exist as all.");
		}
	}

	@Override
	public void deleteAllProduct(List<EBProduct> products) {
		if (!products.isEmpty()) {
			dao.deleteAllProduct(products);
		}
	}

	@Override
	public List<EBProduct> getProdsByCategory(Long categoryId) {
		return dao.getProdsByCategory(categoryId);
	}

	@Override
	public List<EBProduct> getProdsByProdName(String prodName) {
		return dao.getProdsByProdName(prodName);
	}

	@Override
	public List<EBProduct> getProdsByLowestPriceScope(Float low, Float high) {
		return dao.getProdsByLowestPriceScope(low, high);
	}

	@Override
	public List<EBProduct> getProdsByHightestBidPriceScope(Float low, Float high) {
		return dao.getProdsByHightestBidPriceScope(low, high);
	}

	@Override
	public EBProduct getProdById(Long prodId) {
		return dao.getProdById(prodId);
	}

	@Override
	public List<EBProduct> getProds() {
		return dao.getProds();
	}

	@Override
	public List<EBProduct> getProdsByFreightPriceScope(Float low,
			Float high) {
		return dao.getProdsByFreightPriceScope(low, high);
	}

	@Override
	public List<EBProduct> getProdsByFilter(String filter) {
		return dao.getProdsByFilter(filter);
	}

	@Override
	public List<EBProduct> getByProdsId(List<Long> prodsId) {
		return dao.getByProdsId(prodsId);
	}

}
